package com.jysz.certificate.persistence.dao.pm;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.jysz.certificate.persistence.dao.AbstractBaseDao;
import com.jysz.certificate.persistence.enums.pm.PmUserStype;
import com.jysz.certificate.persistence.model.pm.PmUserList;
import com.jysz.certificate.persistence.model.system.Shop;

@Repository
public class PmUserListDao extends AbstractBaseDao<PmUserList, Long> {

	/**
	 * @param monthDate
	 * @param shopids
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<PmUserList> findbyMonthDate(String monthDate,
			List<? extends Object> shopids) {
		Criteria criteria = this.createCriteria();
		
		if(shopids != null && shopids.size() > 0){
			criteria.add(Restrictions.in("shop", shopids));
		}
		criteria.addOrder(Order.asc("organization"));
		
		Criteria pmUserCriteria = criteria.createCriteria("pmUser");
		pmUserCriteria.add(Restrictions.eq("deliceryMM", monthDate));
		pmUserCriteria.add(Restrictions.eq("state", PmUserStype.SUBMITED));
		
		return criteria.list();
	}

	@SuppressWarnings("unchecked")
	public List<PmUserList> findbyMonthDate(String monthDate, Shop shop) {
		Criteria criteria = this.createCriteria();
		
		criteria.add(Restrictions.eq("shop", shop));
		criteria.addOrder(Order.asc("organization"));
		
		Criteria pmUserCriteria = criteria.createCriteria("pmUser");
		pmUserCriteria.add(Restrictions.eq("deliceryMM", monthDate));
		pmUserCriteria.add(Restrictions.eq("state", PmUserStype.SUBMITED));
		
		return criteria.list();
	}

}
